package datasource.c3p0;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import utils.JDBCUtils;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * c3p0的演示
 */
public class C3P0Demo1 {
    public static void main(String[] args)  {
        Connection conn=null;
        PreparedStatement ps=null;
        try {
            //1.创建数据库连接池对象
            DataSource ds  = new ComboPooledDataSource();
            //2. 获取连接对象
           conn = ds.getConnection();

//            //假代码示意用的
//            String sql = "insert into account values(null , ? , ?)";
//            ps = conn.prepareStatement(sql);
//            ps.setString(1, "admi234n");
//            ps.setInt(2, 103200);
//
//            //提交执行
//            ps.executeUpdate();

//            //3. 打印
//            System.out.println(conn);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            JDBCUtils.close(ps, conn);
        }

    }
}
